package com.rds.benchmark.state;

import com.rds.benchmark.command.StableOperators;
import com.rds.benchmark.command.TestOperators;
import com.rds.benchmark.config.ArgvsConfig;
import com.rds.benchmark.operator.*;

public class SelectRun {

    public static void runOperators() throws Exception {
        switch (ArgvsConfig.cmd) {
            case 0:
                if ("jedis".equalsIgnoreCase(ArgvsConfig.clientType))
                    new TestOperators(StringOperator.class, "string").runOperator();
                else if ("redisson".equalsIgnoreCase(ArgvsConfig.clientType))
                    new TestOperators(StringRedissonOperator.class, "string").runOperator();
                else if ("lettuce".equalsIgnoreCase(ArgvsConfig.clientType))
                    new TestOperators(StringLettuceOperator.class, "string").runOperator();
                break;
            case 1:
                new TestOperators(ListOperator.class, "list").runOperator();
                break;
            case 2:
                new TestOperators(SetOperator.class, "set").runOperator();
                break;
            case 3:
                new TestOperators(HashOperator.class, "hash").runOperator();
                break;
            case 4:
                new TestOperators(ZsetOperator.class, "zset").runOperator();
                break;
            case 5:
                new TestOperators(PublishOperator.class, "publish").runOperator();
                break;
            case 6:
                new TestOperators(OneWriteNineReadOperator.class, "w1r9").runOperator();
                break;
            case 7:
                new TestOperators(StringOperator.class, "write").runOperator();
                break;
            case 8:
                new TestOperators(StringOperator.class, "read").runOperator();
                break;
            case 9:
                new TestOperators(StringOperator.class, "write").runOperator();
                new TestOperators(StringOperator.class, "read").runOperator();
                break;
            case 90:
                if ("jedis".equalsIgnoreCase(ArgvsConfig.clientType))
                    new StableOperators(StableStringOperator.class, "string").runOperator();
                else if ("redisson".equalsIgnoreCase(ArgvsConfig.clientType))
                    new StableOperators(StableStringRedissonOperator.class, "string").runOperator();
                else if ("lettuce".equalsIgnoreCase(ArgvsConfig.clientType))
                    new StableOperators(StableStringLettuceOperator.class, "string").runOperator();
                break;
            case 99:
                if(ArgvsConfig.commands != null){
                    for (String command : ArgvsConfig.commands){
                        new TestOperators(RedisBenchmarkOperator.class,command).runOperator();
                    }
                }
                break;
            case 100:
                new TestOperators(StringOperator.class, "string").runOperator();
                new TestOperators(ListOperator.class, "list").runOperator();
                new TestOperators(SetOperator.class, "set").runOperator();
                new TestOperators(HashOperator.class, "hash").runOperator();
                new TestOperators(ZsetOperator.class, "zset").runOperator();
                new TestOperators(PublishOperator.class, "publish").runOperator();
                break;
            default:
                System.out.println("Unknown command");
                ArgvsConfig.Usage();
        }
    }
}
